package com.example.auv_660.command;

import com.example.auv_660.moduleload.ModuleLoad;
import com.example.auv_660.network.tcp.HFTCPBuild;
import com.example.auv_660.network.tcp.ModuleReadHandler;
import com.example.auv_660.network.tcp.ModuleWriteHandler;

import java.util.ArrayList;

public enum AUVPropeller {
    INSTANCE;

    private AUVPropellerCommand auvPropellerCommand;

    AUVPropeller()
    {
        this.auvPropellerCommand = new AUVPropellerCommand();
    }

    public AUVPropellerCommand getAuvPropellerCommand()
    {
        return this.auvPropellerCommand;
    }

    public class AUVPropellerCommand extends AUVCommand
    {
        private ArrayList<ModuleLoad> moduleLoadArrayList;
        private static final String PROPELLER = "PropellerLoad";
        private int number = -1;

        public AUVPropellerCommand()
        {
            moduleLoadArrayList = HFTCPBuild.INSTANCE.getModuleInstance();
            number = getAUVModuleNumber(PROPELLER);
        }

        @Override
        public void writeCommand(String command) {
            if (number != -1)
            {
                ModuleWriteHandler propellerWriteHandler = moduleLoadArrayList.get(number).getWriterHandler();
                if (propellerWriteHandler != null)
                {
                    propellerWriteHandler.sendCommandToModule(command);
                }
            }
        }

        @Override
        public void readCommand() {
            if (number != -1)
            {
                ModuleReadHandler propellerReadHandler = moduleLoadArrayList.get(number).getReadHandler();
                if (propellerReadHandler != null)
                {
                    propellerReadHandler.getMessageFromModule();
                }
            }
        }
    }
}
